package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.Login;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	@GetMapping("queryUserById/{userId}")
	public Result<UserInfo> queryUserById(@PathVariable Long userId){
		UserInfo userInfo = this.userInfoService.getById(userId);
		try {
			Thread.sleep(20);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
		return Result.ok(userInfo);
	}
	@Login
	@GetMapping("isPaidAlbum/{albumId}")
	public Result<Boolean> isPaidAlbum(@PathVariable Long albumId){
		Boolean flag = this.userInfoService.isPaidAlbum(albumId);
		return Result.ok(flag);
	}
	@Login
	@GetMapping("queryPaidTracks/{albumId}")
	public Result<List<UserPaidTrack>> queryPaidTracks(@PathVariable Long albumId){
		List<UserPaidTrack> userPaidTracks = this.userInfoService.queryPaidTracks(albumId);
		return Result.ok(userPaidTracks);
	}
}

